package compiler;

import java.util.HashMap;
import java.util.Map;

public class ProcedureManager {

	Map<String, ProcedureC> procedures = new HashMap<String, ProcedureC>();
	
	//Pokusi se pridat proceduru podle definice
	public boolean declareProcedure( String name ){
		
		System.out.println("Declared procedure " + name);
		ProcedureC new_proc = new ProcedureC();
		new_proc.name = name;
		new_proc.inputVariables = new VariableManager(9990);
		new_proc.code = new Code();
		new_proc.variableManager = new VariableManager(90877);
		procedures.put(name, new_proc);
		getProcedureByName(name);
		
		return true;
	}
	
	public ProcedureC getProcedureByName( String name ){
		ProcedureC ret =  procedures.get(name);
		if ( ret == null ) System.out.print("NULL");
		return ret;
	}
	
	public void addParameter( String procName, String paramName, String paramType ){
		
		ProcedureC proc = getProcedureByName(procName);
		assert( proc != null );
		Type type = TypeManager.parseType(paramName);
		assert( type != Type.ERROR_TYPE_t );
		
		proc.inputVariables.declareVariable( paramName, type );
		System.out.println("new parameter " + paramName + " : " + paramType + " for procedure " + procName );
	}
	
	public boolean issetProcedure( String name ){
		
		return true;
	}
}
